home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 49 / Amiga Format CD49 (2000-01-17)(Future Publishing)(GB)(Track 1 of 3)[!][issue 2000-02].iso / -serious- / comms / other / dc-sx107install / sx / developer / sasc / filecheck.c < prev    next >
C/C++ Source or Header  |  1999-11-29  |  3KB  |  154 lines

  1. /*
  2.  
  3. System-X FileCheck Door (designed for the Conference Based Version!)
  4.  
  5. This source is public domain, do what you want with it!
  6.  
  7. */
  8.  
  9. static const char __version[] = "\0$VER: FileCheck 1.0 ("__DATE__")";
  10.  
  11. #include <time.h>
  12. #include <stdio.h>
  13. #include <string.h>
  14. #include <stdlib.h>
  15. #include <proto/exec.h>
  16. #include <proto/dos.h>
  17. #include "sxstructs.h"
  18.  
  19. struct MsgPort *bbsport;
  20.  
  21. struct JHMessage
  22. {
  23.   struct Message Msg;
  24.   char String[200];
  25.   int Data;
  26.   int Command;
  27. } themsg;
  28.  
  29.  
  30. void PS(char * str);
  31. void XIMFunction(int func, long data, char * str);
  32. void FileCheck(char *fname);
  33.  
  34.  
  35. int main(int argc, char *argv[])
  36. {
  37.     char portname[16];
  38.  
  39.     if(argv[1][0]==0)
  40.     {
  41.         PutStr("This program requires System-X BBS Software\n");
  42.     } else {
  43.         sprintf(portname, "AEDoorPort%s", argv[1]);
  44.         bbsport = FindPort(portname);
  45.         if(bbsport)
  46.         {
  47.             XIMFunction(1, 0, 0);     /* function 1 = register */
  48.  
  49.             FileCheck(argv[2]);
  50.  
  51.             XIMFunction(2, 0, 0);     /* function 2 = shutdown */
  52.         }
  53.     }
  54. }
  55.  
  56. void PS(char * str)
  57. {
  58.     XIMFunction(1500, (long)str, 0);
  59. }
  60.  
  61. void XIMFunction(int func, long data, char * str)
  62. {
  63.     struct MsgPort *replyport;
  64.  
  65.     replyport = CreateMsgPort();
  66.     if(replyport)
  67.     {
  68.         themsg.Msg.mn_Length    = sizeof(struct JHMessage);
  69.         themsg.Msg.mn_ReplyPort    = replyport;
  70.         themsg.Data         = data;
  71.         themsg.Command         = func;
  72.         if(str && str[0]!=0) strcpy(themsg.String, str);
  73.         PutMsg(bbsport, (struct Message *)&themsg);
  74.         WaitPort(replyport);
  75.         DeleteMsgPort(replyport);
  76.     }
  77. }
  78.  
  79. void FileCheck(char *fname)
  80. {
  81.     char buf[256];
  82.     BPTR lck, fh;
  83.  
  84. /* NOTE: \033 is an escape code (ascii 27) */
  85.  
  86.  
  87.     /* == FIRST, LETS CHECK IF THE FILE EXISTS == */
  88.  
  89.     lck = Lock(fname, SHARED_LOCK);
  90.     if(!lck) return;    /* == IF IT DOESN'T, EXIT QUIETLY == */
  91.     UnLock(lck);
  92.  
  93.  
  94.  
  95.     /* == PRINT SOME CREDITS == */
  96.  
  97.     PS("\033[0;33;44m\r\n FileCheck 1.0 for SYSTEM-X - Written By Zed^DC \033[0m\r\n\r\n");
  98.  
  99.  
  100.  
  101.     /* == PRINT THE FILE INFORMATION */
  102.  
  103.     sprintf(buf, "\033[32mChecking File: \033[33m%s\r\n", fname);
  104.     PS(buf);
  105.  
  106.  
  107.  
  108.     /* == LETS DO A SIMPLE CONFERENCE DUPE CHECK == */
  109.  
  110.     fh = Open("SX:Prefs/Confs.DAT", MODE_OLDFILE);
  111.  
  112.     if(fh)
  113.     {
  114.         struct ConfStruct Conf;
  115.  
  116.         while(1)
  117.         {
  118.  
  119.             if(Read(fh, &Conf, sizeof(struct ConfStruct)))
  120.             {
  121.  
  122.                 /* == LET'S CHECK THIS CONFERENCE == */
  123.  
  124.                 sprintf(buf, "\r\n\033[32mCHECKING CONFERENCE: \033[36m%s .. ", Conf.name);
  125.                 PS(buf);
  126.  
  127.                 if(Conf.filepath[0] == 0)
  128.                     lck = 0;
  129.                 else {
  130.                     sprintf(buf, "%s%s", Conf.filepath, fname);
  131.                     lck = Lock(buf, SHARED_LOCK);
  132.                 }
  133.                 if(lck)
  134.                 {
  135.                     UnLock(lck);
  136. /* == FILE IS DUP!! == */        PS("\033[31mDuplicate Found!\033[0m\r\n\r\nFile has been deleted!");
  137.                     DeleteFile(fname);
  138.                     Close(fh);
  139.                     return;
  140.                 } else
  141. /* == FILE IS OK! == */            PS("Ok!");
  142.     
  143.             } else
  144.                 break;    /* == REECHED END OF FILE == */
  145.  
  146.         }
  147.  
  148.         Close(fh);
  149.  
  150.     }
  151.  
  152.     PS("\r\n");
  153. }
  154.